package com.wisezone.net.ex02_socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketDemo {
    public static void main(String args[]) {
        //socket通讯服务端程序  // alt+enter
        int port = 9527;
        try {
            System.out.println("启动服务器，监听端口中...");
            ServerSocket serverSocket = new ServerSocket(port);
            Socket socket = serverSocket.accept(); //监听端口
            System.out.println("创建连接成功 " + socket);

            InputStream in = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String line = br.readLine();
            System.out.println("接收到消息是 :" + line);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
